<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"
	import="java.util.List,java.util.Date,Reservation.UserBean,Application.Dao.ReservationDAO,DomainData.Reservation,java.text.SimpleDateFormat"%>

<%
	String day = request.getParameter("date");
	if (day == null || day.equals("")) {
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		day = formatter.format(new Date());
		
		System.out.println(day);
	}
	
	List<Integer> tables=ReservationDAO.getCurrentOccupiedTableIndex(day);

	int tableID = Integer.parseInt(request.getParameter("tableid"));
	String imageName=tableID+"A.png";
	if(tables.contains(tableID)){
		imageName=tableID+"B.png";
	}
	else{
		imageName=tableID+"A.png";
	}


	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Table<%=" #" + tableID%> Reservation Information</title>
<script src="js/jquery-1.6.2.min.js" type="text/javascript"
	charset="utf-8"></script>
<script src="js/loopedslider.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.16.custom.min.js"></script>
<link type="text/css" href="css/jquery-ui.css" rel="stylesheet" />

<script>
	$(function() {
		$("#datepicker").datepicker({
			dateFormat : 'yy-mm-dd'
		});
	});

</script>
</head>
<body>
	Table<%=" #" + tableID%>
	Please Enter a Date
	</br>
	<form id="Table" action="<%=request.getRequestURL()%>">
		<input type="hidden" name=tableid value=<%=tableID%> /> 
		<input type="text" name="date" id="datepicker" value="<%=day%>" /> 
			
		<input type="image" value="submitname" src="images/refreshButton.png"
			width="50" height="50" border="0" alt="SUBMIT!" name="image">

	</form>
	</br>
	<img src="images/<%=imageName%>" />
	<!-- <img src="images/1A.png" /> -->

	<table width=800>
		<tr bgcolor="#F2F2F2">
			<td>Reservation ID</td>
			<td>From</td>
			<td>To</td>
			<td>Number Of People</td>
			<td>Table ID</td>
		</tr>
		<%

			List<Reservation> rlist = ReservationDAO
					.getReservationsForTableBetweenTime(day + " 00:00:00", day
							+ " 23:59:59", tableID);
			for (int i = 0; i < rlist.size(); i++) {
				Reservation r = rlist.get(i);
				int rID = r.getReservationID();
				out.println("<tr><td>"
						+ r.getReservationID()
						+ "</td><td>"
						+ r.getFrom().toString()
						+ "</td><td>"
						+ r.getTo().toString()
						+ "</td><td>"
						+ r.getNumberOfPeople()
						+ "</td><td>"
						+ r.getTableID()
						+ "</td><td><a href='Reservation.jsp?rid='+rID></a></td></tr>");
			}
		%>
	</table>
</body>
</html>